package com.jash.alipaydemo;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.Toast;

import com.alipay.sdk.app.PayTask;

import java.util.Map;


public class AsyncPayTask extends AsyncTask<String, Void, Map<String, String>> {
    private Activity activity;

    public AsyncPayTask(Activity activity) {
        this.activity = activity;
    }

    @Override
    protected Map<String, String> doInBackground(String... params) {
        Map<String, String> map = new PayTask(activity).payV2(params[0], true);
        return map;
    }

    @Override
    protected void onPostExecute(Map<String, String> map) {
        switch (Integer.parseInt(map.get("resultStatus"))) {
            case 9000:
                Toast.makeText(activity, "订单支付成功", Toast.LENGTH_LONG).show();
                break;
            case 8000:
                Toast.makeText(activity, "正在处理中，支付结果未知", Toast.LENGTH_LONG).show();
                break;
            case 4000:
                Toast.makeText(activity, "订单支付失败", Toast.LENGTH_LONG).show();
                break;
            case 5000:
                Toast.makeText(activity, "重复请求", Toast.LENGTH_LONG).show();
                break;
            case 6001:
                Toast.makeText(activity, "用户中途取消", Toast.LENGTH_LONG).show();
                break;
            case 6002:
                Toast.makeText(activity, "网络连接出错", Toast.LENGTH_LONG).show();
                break;
            case 6004:
                Toast.makeText(activity, "支付结果未知", Toast.LENGTH_LONG).show();
                break;
            default:
                Toast.makeText(activity, "其它支付错误", Toast.LENGTH_LONG).show();
                break;
        }
    }
}
